/*******************************************************************************
 * CBPage.h
 * ComicsBlog
 *
 * Contains an array of news which is made for lazy loading. The lazy loading is
 * performed by using loadNewsFrom:to:.
 *
 * Adrien Bougouin <adrien.bougouin@gmail.com>
 */

#import <Foundation/Foundation.h>

#import "CBNews.h"

#define CBPageUpdatedNotificationName @"cbpage_updated"
#define CBPageErrorNotificationName   @"cbpage_error"
//#define CBPageScriptURL               @"http://maxetx.lescigales.org/comicsblogapp/activity.php"
#define CBPageScriptURL               @"http://www.comicsblog.fr/mobile/export_android.php"
#define CBPageHDImageURL              @"http://www.comicsblog.fr/images/news/crop2_"
#define CBPageImageURL                @"http://www.comicsblog.fr/images/news/crop4_"
#define CBPageFileURL                 @"http://www.comicsblog.fr/zik/"

typedef enum parsing_state_st {
  ID,
  DATE,
  TITLE,
  IMAGE,
  FFILE,
  DESCRIPTION,
  CATEGORY,
  TYPE,
  NOP
} CBParsingState;

@interface CBPage : NSObject<NSXMLParserDelegate> {
  @private
    NSString *_scriptURL;
    NSString *_lastErrorMessage;
    NSMutableArray *_news;
    NSURLConnection *_scriptConnection;
    NSXMLParser *_xmlParser;
    NSMutableData *_tempDatas;
    NSUInteger _tempIdentifier;
    NSMutableString *_tempTitle;
    NSMutableString *_tempPubDate;
    NSMutableString *_tempHDImage;
    NSMutableString *_tempImage;
    NSMutableString *_tempFile;
    NSMutableString *_tempDescription;
    NSUInteger _tempCategory;
    NSMutableString *_tempType;
    CBParsingState _parsingState;
}

@property(nonatomic,
          readonly,
          getter=lastErrorMessage) NSString *_lastErrorMessage;

- (id) initWithCategory:(NSUInteger) category;
- (void) loadNewsFrom:(NSUInteger) from length:(NSUInteger) length;
- (void) notifyWithName:(NSString *) name;
- (void) notifyUpdated;
- (void) notifyError;
- (NSUInteger) numberOfNews;
- (CBNews *) newsAtIndex:(NSUInteger) index;

@end

